package com.xtoad.ecms.baseinfo.controller;

import com.xtoad.ecms.common.web.base.Result;
import com.xtoad.ecms.common.web.annotation.PrintRequestInfo;
import com.xtoad.ecms.common.web.annotation.RequiredToken;
import com.xtoad.ecms.common.web.annotation.ResponseAdvice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * hello 控制器
 *
 * @author xtoad
 * @date 2020/05/29
 */
@RestController
@RequiredToken(value = false)
@RequestMapping("hello")
@ResponseAdvice
public class HelloController {

    private static final Logger LOGGER = LoggerFactory.getLogger(HelloController.class);

    /**
     * Say Hello World
     *
     * @return Hello World
     */
    @PrintRequestInfo
    @RequestMapping(method = RequestMethod.GET)
    public String sayHello() {
        // FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL
        LOGGER.error("Hello World");
        LOGGER.warn("Hello World");
        LOGGER.info("Hello World");
        LOGGER.debug("Hello World");
        LOGGER.trace("Hello World");
        return "Hello World";
    }

    /**
     * Say Hello
     *
     * @param userName 姓名
     * @return Hello 姓名
     */
    @PrintRequestInfo
    @RequestMapping(value = "{userName}", method = RequestMethod.GET)
    public Result<String> say(@PathVariable final String userName) {

        return Result.success("Hello " + userName);
    }

    /**
     * Say Hello
     *
     * @return Hello 姓名
     */
    @PrintRequestInfo
    @RequestMapping(value = "/arr", method = RequestMethod.GET)
    public String[] say() {
        return new String[]{"Hello", "world", "!"};
    }

}
